package com.project.queue.factory;

import com.project.queue.helper.QueuePropertiesHelper;
import com.project.queue.tool.BaseQueue;
import com.project.queue.tool.EmptyQueue;
import com.project.queue.tool.KafkaQueue;
import com.project.queue.tool.RabbitMqQueue;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @author mengxj
 */
@Component
public class QueueFactory implements ApplicationRunner {

    public static final String KAFKA = "kafka";

    public static final String RABBIT_MQ = "rabbitMq";

    private static BaseQueue baseQueue;

    public static BaseQueue getInstance(){
        return baseQueue;
    }

    private void init(){
        String type = QueuePropertiesHelper.type();
        switch (type){
            case KAFKA:
                baseQueue = KafkaQueue.getInstance();
                break;
            case RABBIT_MQ:
                baseQueue = RabbitMqQueue.getInstance();
                break;
            default:
                baseQueue = EmptyQueue.getInstance();
        }
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        this.init();
    }
}
